<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class Domainable {
	public function Domainable()
	{
		global $BBX;
		
		// instantiate memcache
		$BBX['memcache'] = false;
		if (class_exists('Memcache'))
		{
			$memcache = new Memcache();
			if (@$memcache->connect('localhost', 11211))
				$BBX['memcache'] = $memcache;
		}
		
		$host = $_SERVER['HTTP_HOST'];
		
		// parse the url into its defined parts
		$parts 		= parse_url($host);
		$parts_host = isset($parts['host']) ? $parts['host'] : $parts['path']; // DH weirdness where host isn't properly parsed out; php issue?
		
		log_message('debug', 'domain: '.$parts_host);
		
		// determine our subdomain
		$_sub = explode('.', $parts_host);
		if (count($_sub) == 3) // subdomain present
		{
			$BBX['subdomain'] = $_sub[0];
			$host_no_sub	  = preg_replace("/{$_sub[0]}\./", '', $host);
		}
		else
		{
			$BBX['subdomain'] = false;
			$host_no_sub	  = $host;
		}
		$host_no_sub_port = preg_replace("/\:(\d+)$/", '', $host_no_sub);
		
		// store useful goodies in our $BBX superglobal
		$BBX['request']['host']	 	 			 = $host;
		$BBX['request']['subless_host'] 		 = $host_no_sub;
		$BBX['request']['subless_portless_host'] = $host_no_sub_port;
		$BBX['request']['parts'] 	 			 = $parts;
	}
}
?>